home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / Weather / Source / Defaults.m < prev    next >
Text File  |  1993-11-14  |  3KB  |  106 lines

  1. /*
  2.  * Simple default handler.
  3.  * Do 'openDefaults()' at -appDidInit time, reference the global default
  4.  * variables defined here, and write the values back out with 'writeDefaults()'
  5.  * 
  6.  * M. J. Hawley
  7.  * mike@media-lab.mit.edu
  8.  */
  9. /*
  10.     Copyright (c) 1991, 1992 by the MIT Media Laboratory
  11.     
  12.     This software is distributed by Michael Hawley of the MIT Media Laboratory. 
  13.     We hope it will be useful to you.
  14.     
  15.     Permission to use, copy, or modify this software for educational 
  16.     and research purposes only and without fee is hereby granted 
  17.     provided this notice appears on all copies, and provided you send 
  18.     us your improvements.  Any other use of this software, in original 
  19.     or modified form, in whole or in part, requires specific permission 
  20.     from MIT.  This software shall not be used, rewritten, or adapted 
  21.     for use in a commercial product without first obtaining appropriate 
  22.     licenses from MIT.  MIT makes no representations about the suitability 
  23.     of this software for any purpose: it is provided "as is" without any 
  24.     warranty and any risk, damage, or liability incurred through your use 
  25.     of this software is yours alone.
  26.     
  27.     Michael Hawley
  28.     MIT Media Laboratory
  29.     20 Ames Street, 
  30.     Cambridge, MA 02139
  31.     mike@media-lab.mit.edu
  32. */
  33.  
  34. #import "Defaults.h"
  35.  
  36. @implementation Defaults
  37.  
  38. #define appname [NXApp appName]
  39.  
  40. char FirstUsed[1024] = "";
  41. char DefaultFont[256] = "Ohlfs";
  42. char DefaultFontSize[32] = "10.";
  43. char FetchText[3][128] = { "", "", "" };
  44. char Site[80] = "downwind.sprl.umich.edu";
  45.  
  46. static NXDefaultsVector DefaultV = {
  47.     {"FirstUsed",  FirstUsed},
  48.     {"Site",  Site},
  49.     {"Font",  DefaultFont},
  50.     {"FontSize", DefaultFontSize },
  51.     {"Fetch1", FetchText[0] },
  52.     {"Fetch2", FetchText[1] },
  53.     {"Fetch3", FetchText[2] },
  54.     {NULL}
  55. };
  56.  
  57. char *
  58. deflt(char *s){
  59.     return (char *)NXGetDefaultValue(appname,s);
  60. }
  61.  
  62. static id _defaults = (id)0;
  63.  
  64. + loadDefaults {
  65.     char *s;
  66.     extern char *strcpy();
  67. #define l(x,xs) s = deflt(xs); if (s && *s) strcpy(x,s)
  68.     l(FirstUsed,"FirstUsed");
  69.     l(Site,"Site");
  70.     l(DefaultFont,"Font");
  71.     l(DefaultFontSize,"FontSize");
  72.     l(FetchText[0],"Fetch1");
  73.     l(FetchText[1],"Fetch2");
  74.     l(FetchText[2],"Fetch3");
  75.     return self;
  76. }
  77.  
  78. + initialize {
  79.     NXRegisterDefaults(appname, DefaultV);
  80.     [self loadDefaults];
  81.     return self;
  82. }
  83.  
  84. - writeDefaults:sender {
  85.     NXWriteDefaults(appname, DefaultV);
  86.     return self;
  87. }
  88.  
  89. - free {
  90.     [self writeDefaults:self];
  91.     [super free];
  92.     return self;
  93. }
  94.  
  95. void
  96. openDefaults(){
  97.     _defaults = [Defaults new];
  98. }
  99.  
  100. void
  101. writeDefaults(){
  102.     [_defaults writeDefaults:_defaults];
  103. }
  104.  
  105. @end
  106.